package com.ymatou.iapi.trading.operate.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.req.MarkOrderLockReq;
import com.ymatou.iapi.trading.operate.service.MarkOrderLockCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.constant.ECode;
/**
*删除订单
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_MarkOrderLock {
	private static MarkOrderLockReq markOrderLockReq;
	private static MarkOrderLockCall markOrderLockCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("锁定解锁订单");
	}

	@Before
	public void caseUp() {
		markOrderLockReq = new MarkOrderLockReq();
		markOrderLockCall = new MarkOrderLockCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(markOrderLockCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MarkOrderLock_001() {
		Logger.start(true, "锁定订单");
		try {
			//创建订单
			Logger.comment("前置数据准备开始");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");
			//参数

			markOrderLockReq.setOrderId(orderId);
			markOrderLockReq.setLockStatus(1);

			//发送请求
			markOrderLockCall.setData(markOrderLockReq);
			markOrderLockCall.callService();

			Logger.verifyEquals("200", markOrderLockCall.getString("code"),
					"验证code");

			Logger.verifyEquals(true, markOrderLockCall.getSuccess(),
					"验证success");

			//数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(
					1,
					(Integer) database.selectOrderByOderId(orderId).get(0)
							.get("iUnfreezeStatus"), "验证订单表是否锁定状态");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MarkOrderLock_002() {
		Logger.start(true, "解锁订单");
		try {
			//创建订单
			Logger.comment("前置数据准备开始");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");
			//参数

			markOrderLockReq.setOrderId(orderId);
			markOrderLockReq.setLockStatus(0);

			//发送请求
			markOrderLockCall.setData(markOrderLockReq);
			markOrderLockCall.callService();

			Logger.verifyEquals("200", markOrderLockCall.getString("code"),
					"验证code");

			Logger.verifyEquals(true, markOrderLockCall.getSuccess(),
					"验证success");

			//数据库验证
			DefaultWapper database = new DefaultWapper();

			Logger.verifyEquals(
					0,
					(Integer) database.selectOrderByOderId(orderId).get(0)
							.get("iUnfreezeStatus"), "验证订单表是否锁定状态");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_MarkOrderLock_003() {
		Logger.start(false, "订单号为空，删除订单失败");
		try {

			//发送请求
			markOrderLockCall.setData(markOrderLockReq);
			markOrderLockCall.callService();

			Logger.verifyEquals("400", markOrderLockCall.getString("code"),
					"验证code");

			Logger.verifyEquals(false, markOrderLockCall.getSuccess(),
					"验证success");

			Logger.verifyIsContains(ECode.ERROR400_MSG_9,
					markOrderLockCall.getErrorMessage(), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}